package com.aaa.reflection.demo5;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

/**
 * @author C-Q
 * @version 1.1.0
 * @Description: 通过反射类获取方法类对象
 * @date 2022/10/27
 */
public class Test01 {
    public static void main(String[] args)throws Exception {
        Class<Dog> dogClass = Dog.class;
        //1根据方法名称和参数获取本类中指定的方法对象
        Method sleep = dogClass.getDeclaredMethod("sleep");
//        System.out.println(sleep);

        Method each = dogClass.getDeclaredMethod("each", String.class, Integer.class);
        System.out.println("each ==== " + each);
        //2获取本类中所有方法
        Method[] declaredMethods = dogClass.getDeclaredMethods();
//        for (Method method:declaredMethods) {
//            System.out.println("method ==== " + method);
//        }
        //3根据方法名和参数类型获取本类以及父类中指定public的方法对象
        Method fan = dogClass.getMethod("fan");
//        System.out.println("fan ==== " + fan);
        Method sleep1 = dogClass.getMethod("sleep");
//        System.out.println("sleep1 ==== " + sleep1);

        //4获取本类及其父类中所有的public方法对象
        Method[] methods = dogClass.getMethods();
//        for (Method method01:methods) {
//            System.out.println("method01 === " + method01);
//        }
    }
}



class Cat{
    public void fan(){
        System.out.println("风扇的fan方法");
    }
    private void fan01(){
        System.out.println("风扇的fan01方法");
    }
}
class Dog extends Cat {
    public void sleep(){
        System.out.println("Dog中的sleep方法");
    }
    public void each(String job,Integer time){
        System.out.println("Dog中的each方法");
    }
}